package org.bean2sql.demo;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.List;

import org.bean2sql.BeanSqlGenerator;
import org.bean2sql.generator.SqlCommand;

public class Demo {

    public static void main(String[] args) {
        Person person = new Person();
        person.setId(1);
        person.setName("John Harald");
        person.setEmail("harald@web.de");

        Person person2 = new Person();
        person2.setId(2);
        person2.setName("Albert Miller");
        person2.setEmail("miller@mills.com");

        List<Object> beanList = new ArrayList<Object>();
        beanList.add(person);
        beanList.add(person2);

        BeanSqlGenerator sqlGen = new BeanSqlGenerator();
        sqlGen.setDateFormat("yyyy/MM/dd");
        
        try {
            String sql = sqlGen.getSql(SqlCommand.CREATE, person, "");
            System.out.println("[CREATE TABLE SQL output] \n" + sql);

            System.out.println("");

            sql = sqlGen.getSql(SqlCommand.INSERT, person, "");
            System.out.println("[Single INSERT SQL output] \n" + sql);

            System.out.println("");

            List<String> batch = sqlGen.getSql(SqlCommand.INSERT, beanList, "");
            System.out.println("[Multiple INSERT SQL output]");
            for (String sqlItem : batch) {
                System.out.println(sqlItem);
            }

            System.out.println("");

            person.setBirth(DateFormat.getDateInstance().parse("10/05/1960"));
            sql = sqlGen.getSql(SqlCommand.UPDATE, person, "");
            System.out.println("[Single UPDATE SQL output]\n" + sql);

            System.out.println("");

            sql = sqlGen.getSql(SqlCommand.DELETE, person, "");
            System.out.println("[Single DELETE SQL output]\n" + sql);
        } catch (Exception e) {
            System.out.println("ERROR!!!!!!");
            e.printStackTrace();
        }
    }
}
